/*
 * Copyright 2025 Haiku, Inc. All rights reserved.
 * Distributed under the terms of the MIT License.
 */
#ifndef _ANT_CONTROL_LOOK_H
#define _ANT_CONTROL_LOOK_H

#include <ControlLook.h>
#include "HaikuControlLook.h"
#include <algorithm>

class BBitmap;
class BControl;
class BGradientLinear;
class BView;

namespace BPrivate {

class AntControlLook : public HaikuControlLook {
public:
							AntControlLook();
	virtual				~AntControlLook();

	virtual BAlignment		DefaultLabelAlignment() const;
	virtual float			DefaultLabelSpacing() const;

	virtual	float			DefaultItemSpacing() const;

	virtual uint32			Flags(BControl* control) const;

	// Ant Design风格的按钮框架绘制
	virtual	void			DrawButtonFrame(BView* view, BRect& rect,
							const BRect& updateRect,
							const rgb_color& base,
							const rgb_color& background,
							uint32 flags = 0,
							uint32 borders = B_ALL_BORDERS);
	virtual	void			DrawButtonFrame(BView* view, BRect& rect,
							const BRect& updateRect,
							float radius,
							const rgb_color& base,
							const rgb_color& background,
							uint32 flags = 0,
							uint32 borders = B_ALL_BORDERS);

	// Ant Design风格的按钮背景绘制
	virtual	void			DrawButtonBackground(BView* view, BRect& rect,
							const BRect& updateRect,
							const rgb_color& base,
							uint32 flags = 0,
							uint32 borders = B_ALL_BORDERS,
							orientation orientation = B_HORIZONTAL);
	virtual	void			DrawButtonBackground(BView* view, BRect& rect,
							const BRect& updateRect,
							float radius,
							const rgb_color& base,
							uint32 flags = 0,
							uint32 borders = B_ALL_BORDERS,
							orientation orientation = B_HORIZONTAL);

	// Ant Design风格的复选框绘制
	virtual	void			DrawCheckBox(BView* view, BRect& rect,
							const BRect& updateRect,
							const rgb_color& base,
							uint32 flags = 0);

	// Ant Design风格的单选按钮绘制
	virtual	void			DrawRadioButton(BView* view, BRect& rect,
							const BRect& updateRect,
							const rgb_color& base,
							uint32 flags = 0);

	// Ant Design风格的菜单背景绘制
	virtual	void			DrawMenuBackground(BView* view,
							BRect& rect, const BRect& updateRect,
							const rgb_color& base, uint32 flags = 0,
							uint32 borders = B_ALL_BORDERS);

	// Ant Design风格的菜单项背景绘制
	virtual	void			DrawMenuItemBackground(BView* view,
							BRect& rect, const BRect& updateRect,
							const rgb_color& base, uint32 flags = 0,
							uint32 borders = B_ALL_BORDERS);

	// Ant Design风格的状态栏绘制
	virtual	void			DrawStatusBar(BView* view, BRect& rect,
							const BRect& updateRect,
							const rgb_color& base,
							const rgb_color& barColor,
							float progressPosition);

	// Ant Design风格的滑块颜色
	virtual	rgb_color		SliderBarColor(const rgb_color& base);

	// Ant Design风格的滑块栏绘制
	virtual	void			DrawSliderBar(BView* view, BRect rect,
							const BRect& updateRect,
							const rgb_color& base,
							rgb_color leftFillColor,
							rgb_color rightFillColor,
							float sliderScale, uint32 flags,
							orientation orientation);

	// Ant Design风格的滑块拇指绘制
	virtual	void			DrawSliderThumb(BView* view, BRect& rect,
							const BRect& updateRect,
							const rgb_color& base, uint32 flags,
							orientation orientation);

	// Ant Design风格的文本控件边框绘制
	virtual	void			DrawTextControlBorder(BView* view, BRect& rect,
							const BRect& updateRect,
							const rgb_color& base, uint32 flags = 0,
							uint32 borders = B_ALL_BORDERS);

	// Ant Design风格的标签绘制
	virtual	void			DrawLabel(BView* view, const char* label,
							BRect rect, const BRect& updateRect,
							const rgb_color& base, uint32 flags,
							const BAlignment& alignment,
							const rgb_color* textColor = NULL);

	// Ant Design风格的标签和图标绘制
	virtual	void			DrawLabel(BView* view, const char* label,
							const BBitmap* icon, BRect rect,
							const BRect& updateRect,
							const rgb_color& base, uint32 flags,
							const BAlignment& alignment,
							const rgb_color* textColor = NULL);

	// Ant Design 5 色彩系统API
	// 主题设置
	enum ThemeMode {
		LIGHT,
		DARK
	};
	
	void SetThemeMode(ThemeMode mode);
	ThemeMode GetThemeMode() const;

	// 获取品牌色
	rgb_color GetPrimaryColor(int level = 6) const;
	// 获取成功色
	rgb_color GetSuccessColor(int level = 6) const;
	// 获取警告色
	rgb_color GetWarningColor(int level = 6) const;
	// 获取错误色
	rgb_color GetErrorColor(int level = 6) const;
	
	// 获取文本色
	rgb_color GetTextPrimaryColor() const;
	rgb_color GetTextSecondaryColor() const;
	rgb_color GetTextDisabledColor() const;
	
	// 获取边框色
	rgb_color GetBorderColor() const;
	
	// 获取背景色
	rgb_color GetBackgroundColor() const;
	rgb_color GetTableHeaderColor() const;

	// 色彩辅助函数
	// 获取悬停状态的颜色（通常比基础色更亮）
	rgb_color GetHoverColor(const rgb_color& base) const;
	
	// 获取激活状态的颜色（通常比基础色更暗）
	rgb_color GetActiveColor(const rgb_color& base) const;
	
	// 获取禁用状态的颜色（通常降低饱和度并增加亮度）
	rgb_color GetDisabledColor(const rgb_color& base) const;
	
	// 获取对比色（用于在背景色上显示文本）
	rgb_color GetContrastColor(const rgb_color& background) const;

	// 绘制主要按钮
	void DrawPrimaryButton(BView* view, BRect& rect,
						const BRect& updateRect,
						const rgb_color& base,
						uint32 flags = 0);

	// 绘制次要按钮
	void DrawSecondaryButton(BView* view, BRect& rect,
						const BRect& updateRect,
						const rgb_color& base,
						uint32 flags = 0);

	// 绘制输入框
	void DrawTextInput(BView* view, BRect& rect,
					const BRect& updateRect,
					const rgb_color& base,
					uint32 flags = 0);

private:
	// Ant Design 5 色彩系统常量
	// 品牌色梯度
	static const rgb_color kAntPrimaryColors[10];
	// 成功色梯度
	static const rgb_color kAntSuccessColors[10];
	// 警告色梯度
	static const rgb_color kAntWarningColors[10];
	// 错误色梯度
	static const rgb_color kAntErrorColors[10];
	// 中性色
	static const rgb_color kAntTextPrimary;   // 主要文本色
	static const rgb_color kAntTextSecondary; // 次要文本色
	static const rgb_color kAntTextDisabled;  // 禁用文本色
	static const rgb_color kAntBorder;        // 边框色
	static const rgb_color kAntBackground;    // 背景色
	static const rgb_color kAntTableHeader;   // 表格头部背景色
	
	// 暗色主题色彩
	static const rgb_color kAntDarkBackground;      // 暗色背景
	static const rgb_color kAntDarkComponentBg;      // 暗色组件背景
	static const rgb_color kAntDarkSecondaryBg;      // 暗色次级背景
	static const rgb_color kAntDarkBorder;           // 暗色边框
	static const rgb_color kAntDarkTextPrimary;      // 暗色主文本
	static const rgb_color kAntDarkTextSecondary;    // 暗色次文本
	static const rgb_color kAntDarkTextDisabled;     // 暗色禁用文本

	// 圆角半径常量
	static const float kRadius = 2.0f;

	// 当前主题模式
	ThemeMode fThemeMode;
};

}  // namespace BPrivate

#endif // _ANT_CONTROL_LOOK_H

}

#endif // _ANT_CONTROL_LOOK_H